package com.relsell.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;

import com.relsell.pointofsales.R;
import com.relsell.utility.AppVars;
import com.relsell.utility.UserPin;
import com.relsell.utility.UtilitySingleTon;
import com.relsell.view.Manager.TabsAdapter;

public class ManagerReports extends Fragment {

	private ExpandableListView expListView;
	private ExpandableListAdapterForManager listAdapter;
	private HashMap<Integer, Integer> listDataHeader;
	private List<String> listDataChild;
	private View tabOne;
	private View tabBarOne;
	private View tabTwo;
	private View tabBarTwo;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.list_exp_main, container, false);
		UtilitySingleTon.getInstance().createDummyArrayListofUserPin(getActivity());
		expListView = (ExpandableListView) v.findViewById(R.id.lvExp);
		prepareData();
		listAdapter = new ExpandableListAdapterForManager(this.getActivity(),
				listDataHeader, listDataChild);
		expListView.setAdapter(listAdapter);
		expListView.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				Toast.makeText(
						getActivity(),
						"Month is " + listDataHeader.get(groupPosition)
								+ "Week is" + listDataChild.get(childPosition),
						Toast.LENGTH_SHORT).show();
				UtilitySingleTon.getInstance().createDummyFilteredArrayList(AppVars.sUserPinList);
				UtilitySingleTon.getInstance().getTabHost().setCurrentTab(1);
				UtilitySingleTon.getInstance().drawMapOptions(
						UtilitySingleTon.getInstance().getMap(),
						ManagerReports.this.getActivity(),
						AppVars.sFilteredUserPinList);
				return true;
			}
		});

		return v;

	}

	private void prepareData() {
		listDataHeader = new HashMap<Integer, Integer>();
		listDataChild = new ArrayList<String>();
		int i = 0;
		for (UserPin localObj : AppVars.sUserPinList) {
			if (!listDataHeader.containsValue(localObj.getMonth())) {
				listDataHeader.put(i, localObj.getMonth());
				if (localObj.getWeek() == 0) {
					listDataChild.add("0");
				} else if (localObj.getWeek() == 1) {
					listDataChild.add("1");
				} else if (localObj.getWeek() == 2) {
					listDataChild.add("2");
				} else if (localObj.getWeek() == 3) {
					listDataChild.add("3");
				} else if (localObj.getWeek() == 4) {
					listDataChild.add("4");
				}
				i++;
			}
		}
	}

}
